package com.wdg.service.impl;

import com.wdg.dao.IAroundeqDao;
import com.wdg.dao.IUserCenterDao;
import com.wdg.pojo.*;
import com.wdg.service.IUserCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserCenterServiceImpl implements IUserCenterService {

    @Resource
    private IUserCenterDao userCenterDao;

    @Autowired
    private IAroundeqDao aroundeqDao;

    @Override
    public List<Cookbook> getCookBookByUid(int uid) {

        List<Cookbook> cookBookBy = userCenterDao.getCookBookByUid(uid);

        for (Cookbook cookbook : cookBookBy) {
            cookbook.setStaroffs(aroundeqDao.getStaroffList(cookbook.getCbid()));
        }
        return cookBookBy;
    }
    @Override
    public List<Topic> getTopicByUid(int page, int uid) {
        //int p = page * 2 -1;

        List<Topic> topic = userCenterDao.getTopic(page,uid);

        for (Topic t:topic) {
            t.setImage(getTopicImage(t.getTid()));
            t.setComments(getAllComment(t.getTid()));
        }

        return topic;
    }

    @Override
    public List<TopicImage> getTopicImage(String tid) {
        return userCenterDao.getTopicImage(tid);
    }

    @Override
    public List<Comment> getAllComment(String tid) {
        return userCenterDao.getAllComment(tid);
    }

    //我的收藏和关注
    @Override
    public List<User> getMyFocus(String uid) {
        return userCenterDao.getMyFocus(uid);
    }

    @Override
    public List<Cookbook> getMyStatoff(String uid) {
        return userCenterDao.getMyStatoff(uid);
    }
}
